/**
 * fileName: BaseAction.java
 *     Date: 2012-4-28
 **/
package com.stranger.common.core;



import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;



import com.opensymphony.xwork2.ActionSupport;
import com.stranger.common.bean.MessageCode;
import com.stranger.common.bean.OrderBean;

import com.stranger.common.util.Pager;
import com.sun.jmx.snmp.ThreadContext;




/**
 * @作者 stranger.lin
 *
 * @时间 2012-4-28
 */
public class BaseAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2648908006325782260L;
	
	private HttpServletRequest  request;
	private HttpServletResponse response;
	
	private Pager pager=new Pager();
	
	private MessageCode msg;
	private OrderBean order;

	protected void queryWithPager(PagerCallBack call){
		if (pager==null) {
			pager=new Pager();
		}
		if (order==null) {
			order=new OrderBean();
		}
		int cureentPageNum=Integer.parseInt(getRequest().getParameter("page"));
		int pageSize=Integer.parseInt(getRequest().getParameter("rows"));
		order.setSidx(getRequest().getParameter("sidx"));
		order.setSorder(getRequest().getParameter("sord"));
		
		pager.setPageSize(pageSize);
		pager.setPage(cureentPageNum);
		ThreadContext.push("pager", pager);
		ThreadContext.push("order", order);
		List<?> list= call.callList();
		pager.setRows(list);
		pager.setRecords(pager.getRecords());

		//return pager;
	}
	

	public HttpServletRequest getRequest() {
		this.request=ServletActionContext.getRequest();
		return request;
	}


	public Pager getPager() {
		return pager;
	}


	public void setPager(Pager pager) {
		this.pager = pager;
	}





	public void setMsg(MessageCode msg) {
		this.msg =msg;
		
	}


	public MessageCode getMsg() {
		return msg;
	}


	public HttpServletResponse getResponse() {
		this.response=ServletActionContext.getResponse();
		return response;
	}
	
	

}
